package com.poetize.plus.entity.vo.page;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.poetize.plus.entity.po.TimeLine;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zuosy
 * @created 2024/5/13 14:24
 */
public record TimeLinePageVO(

        @Schema(description = "ID")
        Long id,

        @Schema(description = "发生时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime occurrenceTime,

        @Schema(description = "内容")
        String content,

        @Schema(description = "创建时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime createTime,

        @Schema(description = "修改时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime updateTime
) {

    /**
     * 实体集合转分页集合
     * @param list
     * @return
     */
    public static List<TimeLinePageVO> convertPageList(List<TimeLine> list){
        List<TimeLinePageVO> result = new ArrayList<>();
        list.forEach(timeLine -> {
            TimeLinePageVO vo = new TimeLinePageVO(timeLine.getId(), timeLine.getOccurrenceTime(), timeLine.getContent(), timeLine.getCreateTime(), timeLine.getUpdateTime());
            result.add(vo);
        });
        return result;
    }
}
